﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox1.Text;
            string password = TextBox2.Text;
            string email = TextBox3.Text;
            string intro = TextBox4.Text;
            string constr = "server=.;uid=sa;pwd=123456;database=Student_db";
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            string sql = "insert into StudentInfo(stu_name,password,email,intro)values(@name,@pwd,@email,@intro)";
            SqlParameter[] pars ={
               new SqlParameter("@name",name),
               new SqlParameter("@pwd",password),
               new SqlParameter("@email",email),
               new SqlParameter("intro",intro)
           };
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.Parameters.AddRange(pars);
            int result = cmd.ExecuteNonQuery();
            if (result>0)
            {
                Literal1.Text = "注册成功<a href='WebForm1.aspx'>跳转到登陆页面 </a>";
            }
            else
            {
                Literal1.Text = "注册失败！";
            }
        }
    }
}